import axiosInstance from "../api";
import {
    ISongQueryParams,
    ICoverQueryParams,
    IStarQueryParams,
} from "../types";

// 歌曲列表 分页模糊查询
export function selectSongPageData(params: ISongQueryParams) {
    return axiosInstance({
        method: "get",
        params: params,
        url: "/api/song",
    });
}

// 我喜欢的歌曲
export function selectStarredSongs(params: ISongQueryParams) {
    return axiosInstance({
        method: "get",
        params: {
            ...params,
            starred: true,
        },
        url: "/api/song",
    });
}

export function getSongCover(params: ICoverQueryParams) {
    return axiosInstance({
        method: "get",
        params: {
            ...params,
        },
        url: "/rest/getCoverArt",
    });
}

// 收藏/取消收藏
export function toggleSongStar(params: IStarQueryParams) {
    const starred = params.starred;
    if (params.starred) {
        delete params.starred;
    }
    if (!starred) {
        return axiosInstance({
            method: "get",
            params: {
                f: "json",
                v: "1.8.0",
                c: "NavidromeUI",
                ...params,
            },
            url: "/rest/star",
        });
    } else {
        params.starred && delete params.starred;
        return axiosInstance({
            method: "get",
            params: {
                f: "json",
                v: "1.8.0",
                c: "NavidromeUI",
                ...params,
            },
            url: "/rest/unstar",
        });
    }
}
